package com.example.yunifang.adapter;

import java.util.ArrayList;

import com.example.yunifang.R;
import com.example.yunifang.bean.XiangQingBean.Data.Comments;
import com.example.yunifang.myview.MyImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PinLunAdapter extends BaseAdapter {
	ArrayList<Comments> data;
	Context context;

	public PinLunAdapter(ArrayList<Comments> data, Context context) {
		super();
		this.data = data;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder=null;
		if(convertView==null){
			convertView=View.inflate(context, R.layout.pinlun_list_item, null);
			holder=new ViewHolder();
			holder.img=(MyImageView) convertView.findViewById(R.id.pinlun_list_item_img);
			holder.name=(TextView) convertView.findViewById(R.id.pinlun_list_item_name);
			holder.title=(TextView) convertView.findViewById(R.id.pinlun_list_item_title);
			holder.time=(TextView) convertView.findViewById(R.id.pinlun_list_item_time);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		ImageLoader.getInstance().displayImage(data.get(position).user.icon, holder.img);
		holder.name.setText(data.get(position).user.nick_name);
		holder.title.setText(data.get(position).content);
		holder.time.setText(data.get(position).createtime);
		return convertView;
	}
	public class ViewHolder{
		MyImageView img;
		TextView name;
		TextView title;
		TextView time;
	}

}
